#define ElemType int

typedef struct ListNode List_Node;

#include "common.h"

char* multiply(char* num1, char* num2);

int main()
{
	//char* num1 = "123"; char* num2 = "456";
	char* num1 = "0";
	char* num2 = "9";
	multiply(num1, num2);
	return 0;
}

char* multiply(char* num1, char* num2)
{
	unsigned len1 = strlen(num1), len2 = strlen(num2);
	unsigned char* res = calloc(len1 + len2 + 1, sizeof(char));
	if (num1[0] == '0' || num2[0] == '0') {
		*(res + 1) = '0';
		return res + 1;
	}

	for (int i = len1 - 1; i >= 0; i--) {
		unsigned char a = num1[i] - '0';
		for (int j = len2 - 1; j >= 0; j--) {
			unsigned b = num2[j] - '0';
			unsigned mul = a * b;
			/* 累加上进位来的值 */
			mul += res[i + j + 1];
			res[i + j + 1] = mul % 10;
			res[i + j] += mul / 10;
		}
	}

	unsigned char bias = '0';
	for (int i = 0; i < len1 + len2; i++)
		res[i] += bias;

	for (int i = 0; i < len1 + len2; i++)
		if (res[i] != '0')
			return res + i;

	return NULL;
}
